local getCanxuMark = function (player)
  local mark = player:getMark("canxu_viewas-turn")
  return type(mark) == "table" and mark or nil
end

local canxu = fk.CreateSkill{
  name = "plum__canxu_viewas&",

  dynamic_desc = function (self, player, lang)
    local mark = getCanxuMark(player)
    if not mark then return "" end
    return "plum__canxu_viewas_inner:"
    ..table.concat(table.map(mark[1], function (n) return "【"..Fk:translate(n).."】" end), "、")..":"
    .."【"..table.concat(table.map(mark[2], function (n) return Fk:translate(n) end), "/").."】"
  end
}

Fk:loadTranslationTable{
  [canxu.name] = "掺虚",
  [":"..canxu.name] = "",

  [":plum__canxu_viewas_inner"] = "你的{1}视为{2}。"
}

local U = require "packages/utility/utility"

canxu:addEffect("viewas", {
  mute = true,
  card_num = 1,
  pattern = "slash,jink,peach,analeptic,shade",
  interaction = function (self, player)
    local mark = getCanxuMark(player)
    if not mark then return end
    local all_choices = mark[2]
    local choices = player:getViewAsCardNames("plum__canxu", all_choices)
    return UI.CardNameBox { choices = choices, all_choices = all_choices, }
  end,
  card_filter = function (self, player, to_select, selected)
    local mark = getCanxuMark(player)
    if not mark then return false end
    return #selected == 0 and table.contains(mark[1], Fk:getCardById(to_select).trueName)
  end,
  view_as = function (self, player, cards)
    if not (#cards == 1 and self.interaction.data) then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = "plum__canxu"
    return card
  end,
})

return canxu
